package main

import "fmt"

type ListNode struct {
	Val  int
	Next *ListNode
}

func reverseList(head *ListNode) *ListNode {
	temp := head
	arr := []int{}
	for {
		if temp == nil {
			break
		}
		arr = append(arr, temp.Val)
		temp = temp.Next
	}
	fmt.Println(arr)
	temp = &ListNode{}
	temp1 := temp
	for i := len(arr) - 1; i >= 0; i-- {
		node := &ListNode{}
		node.Val = arr[i]
		temp1.Next = node
		temp1 = temp1.Next
	}
	return temp
}
func main() {
	head := &ListNode{}
	node1 := &ListNode{1, nil}
	node2 := &ListNode{2, nil}
	node3 := &ListNode{3, nil}
	node4 := &ListNode{4, nil}
	node5 := &ListNode{5, nil}
	head.Next = node1
	node1.Next = node2
	node2.Next = node3
	node3.Next = node4
	node4.Next = node5
	temp := reverseList(head.Next)
	l := temp
	for {
		if l == nil {
			break
		}
		fmt.Printf("[%d]=>", l.Val)
		l = l.Next
	}
}
